﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using Geleximco.Common;
using System.Web;

namespace Geleximco.Web.Provider {
    /// <summary>
    /// Role provider use group type of the user to create the roles for the user.
    /// </summary>
    public class CustomRoleProvider : RoleProvider {

        private string m_applicationName;

        public override void AddUsersToRoles(string[] usernames, string[] roleNames) {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Get the role of user through the actor type of the actor to which user belongs.
        /// </summary>
        /// <param name="username">user name, we don't need the user name as
        /// we already store the user information in session after sucessfull login</param>
        /// <returns>user role</returns>
        public override string[] GetRolesForUser(string username) {

            //if (SessionHelper.CurrentUserRole != UserType.None) {
            //    return new string[] { SessionHelper.CurrentUserRole.ToString() };
            //}

            //UserTds.UserRow user = null;
            //using (IUserManager userMgr = ComponentLocator.Get<IUserManager>()) {
            //    UserTds userTds = userMgr.GetUserByEmail(username);
            //    user = userTds.Users[0];
            //}

            //ActorTds actorTds = null;
            //using (IActorManager actorManager = ComponentLocator.Get<IActorManager>()) {
            //    actorTds = actorManager.GetActor(user.ActorID);
            //}

            //ActorType actorType = (ActorType)Enum.Parse(typeof(ActorType),
            //                                    actorTds.Actors[0].ActorTypeCode);
            //UserType role = UserType.None;
            //switch (actorType) {
            //    case ActorType.MDC:
            //        if (!user.IsUserPermissionNull() && user.UserPermission == 1) {
            //            role = UserType.MDCSuperUser;
            //        } else {
            //            role = UserType.MDC;
            //        }
            //        break;
            //    case ActorType.OP:
            //        role = UserType.OP;
            //        break;
            //    case ActorType.MD:
            //        role = UserType.MD;
            //        break;
            //    case ActorType.Hyg:
            //        role = UserType.Hyg;
            //        break;
            //    default:
            //        // Consider the user as LaboHB if we don't have the context of current folder.
            //        role = UserType.LaboHB;
            //        break;
            //}

            //SessionHelper.CurrentUserRole = role;
            //return new string[] { role.ToString() };
            return new string[] {  };
        }

        public override bool IsUserInRole(string username, string roleName) {
            //return SessionHelper.CurrentUserRole.ToString() == roleName;
            return true;
        }

        public override string ApplicationName {
            get {
                return m_applicationName;
            }
            set {
                m_applicationName = value;
            }
        }

        public override void CreateRole(string roleName) {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch) {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles() {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName) {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName) {
            throw new NotImplementedException();
        }
    }
}
